<?php

namespace app\common\model;


class DiyHome extends Base
{

    protected $name = "diy_home";

    protected $deleteTime = "delete_time";


    public function getStatusList()
    {
        return ['0' => '禁用', '1' => '启用',];
    }

    /**
     * @param int $id
     * @return bool
     * @throws \think\Exception
     */
    public function setRelease(int $id = 0): bool
    {
        //更新所有
        $update_data = [
            'is_release' => 0,
            'update_time' => time()
        ];
        $res = $this->where('delete_time', '=', null)->update($update_data);

        if ($res) {
            $result = $this->where('id', $id)
                ->save(['is_release' => 1, 'update_time' => time()]);
            if ($result) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }

    }

    /**
     * 查询首页显示diy
     * @return DiyHome|array|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getDiyHomeByList()
    {
        return $this->where('is_release', 1)
            ->where('status', 1)
            ->find();
    }

}